package cn.edu.sdu.sol.intake_system.controller;

import cn.edu.sdu.sol.intake_system.model.vo.DataRequest;
import cn.edu.sdu.sol.intake_system.model.vo.DataResponse;
import cn.edu.sdu.sol.intake_system.service.*;
import cn.edu.sdu.sol.intake_system.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api/admin")
public class AdminController {
    @Autowired
    private PersonService userService;
    @Autowired
    private AdminService adminService;

    @Autowired
    private QuestionService questionService;

    @Autowired
    private WillService willService;

    @Autowired
    private ScoreService scoreService;
    @Autowired
    JwtUtil jwtUtil;

    @Autowired
    ImgService imgService;

    @PostMapping("/hello")
    public DataResponse hello() {
        System.out.println("------------------hello, admin-----------------");

        return new DataResponse(200, null, "ok");
    }

    @PostMapping("/questionEdit")
    public DataResponse questionEdit(@RequestBody DataRequest dataRequest,
                                     @RequestHeader("Authorization") String token) {
        return questionService.questionEdit(dataRequest, token);
    }

    @PostMapping("/updateinf")
    public DataResponse updateinf(@RequestBody DataRequest dataRequest,
                                  @RequestHeader("Authorization") String token) {
        return adminService.update(dataRequest, token);
    }

    @PostMapping("/getAdminInf")
    public DataResponse getAdminInf(@RequestHeader("Authorization") String token) {
        return adminService.getAdminInf(token);
    }

    @PostMapping("/updateDepartment")
    public DataResponse updateDepartment(@RequestBody DataRequest dataRequest,
                                         @RequestHeader("Authorization") String token) {
        return adminService.updateDepartment(dataRequest, token);
    }

    @PostMapping("/getQuestion")
    public DataResponse getQuestion(@RequestBody DataRequest dataRequest,
                                    @RequestHeader("Authorization") String token) {
        return questionService.getQuestion(dataRequest, token);
    }

    @PostMapping("/getDepartmentInf")
    public DataResponse getDepartmentInf(@RequestBody DataRequest dataRequest,
                                         @RequestHeader("Authorization") String token) {
        return adminService.getDepartmentInf(dataRequest, token);
    }

    @PostMapping("/getApplicationInf")
    public DataResponse getApplicationInf(@RequestBody DataRequest dataRequest,
                                          @RequestHeader("Authorization") String token) {
        return willService.getApplicationInf(dataRequest, token);
    }

    @PostMapping("/getAllApplicationInf")
    public DataResponse getAllApplicationInf(@RequestBody DataRequest dataRequest) {
        return willService.getAllApplicationInf(dataRequest);
    }

    @PostMapping("/getPersonInf")
    public DataResponse getPersonInf(@RequestBody DataRequest dataRequest,
                                     @RequestHeader("Authorization") String token) {
        return adminService.getPersonInf(dataRequest, token);
    }

    @PostMapping("/passPen")
    public DataResponse passPen(@RequestBody DataRequest dataRequest,
                                @RequestHeader("Authorization") String token) {
        return scoreService.passPen(dataRequest, token);
    }

    @PostMapping("/passFace")
    public DataResponse passFace(@RequestBody DataRequest dataRequest,
                                 @RequestHeader("Authorization") String token) {
        return scoreService.passFace(dataRequest, token);
    }

    @PostMapping("/pass")
    public DataResponse pass(@RequestBody DataRequest dataRequest,
                             @RequestHeader("Authorization") String token) {
        return scoreService.pass(dataRequest, token);
    }

    @PostMapping("/getPassedPerson")
    public DataResponse getPassedPerson(@RequestBody DataRequest dataRequest,
                                        @RequestHeader("Authorization") String token) {
        return adminService.getPassedPerson(dataRequest, token);
    }

    @PostMapping("/deleteWill")
    public DataResponse deleteWill(@RequestBody DataRequest dataRequest,
                                   @RequestHeader("Authorization") String token) {
        return willService.deleteWill(dataRequest, token);
    }

    @PostMapping("/uploadDepartmentImg")
    public DataResponse uploadDepartmentImage(@RequestParam("file") MultipartFile file,
                                              @RequestParam("filename") String filename,
                                              @RequestHeader("Authorization") String token,
                                              @RequestParam("departmentId") Integer departmentId) {
        return imgService.uploadDepartmentImage(file, filename, token, departmentId);
    }

    @PostMapping("/saveInterviewRecord")
    public DataResponse saveInterviewRecord(@RequestBody DataRequest dataRequest,
                                   @RequestHeader("Authorization") String token) {
        return scoreService.saveInterviewRecord(dataRequest, token);
    }

}
